import java.util.Arrays;

public class MyStack {
    private int[] elem;
    private int usedSize;
    public MyStack() {
        elem = new int[5];
    }

    public void push(int val) {
        if (isFull()) {
            elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize++] = val;
    }

    public boolean isFull() {
        return elem.length == usedSize;
    }
    //删除顶峰元素
    public int pop() {
        if (isEmpty()) {
           throw new EmptyStackException();
        }
        int last = elem[usedSize-1];
        usedSize--;
        return last;
    }

    //获取顶峰元素
    public int peek() {
        if (isEmpty()) {
            throw new EmptyStackException();
        }
        return elem[usedSize-1];
    }

    public boolean isEmpty() {
        return usedSize == 0;
    }


}
